(function(){
  var hpWrite_token = GetUrlString("hpWriteToken");
  if(hpWrite_token) localStorage.setItem("hpWrite_token",hpWrite_token);
  var hpLogin_token = GetUrlString("hpLoginToken");
  if(hpLogin_token) localStorage.setItem("hpLogin_token",hpLogin_token);
  // alert(hpWrite_token);alert(hpLogin_token)

  var cityName = localStorage.getItem("cityName");
  $("#cCity").text(cityName);
})();

// 搜索关键词
$(".search").on("keyup",function(){
  var keywords = $(this).val();
  var city = $("#cCity").text();
  $.ajax({
      type:'get',
      url:address+'/newBuildings/listNewBuildingNames.do',
      data:{
        "keywords":keywords,
        "city":city
      },
      dataType:'json',
      success:function(result){
        if(result.status ==200){
            var html = "";
            $.each(result.data.list,function(index,info){
                html +='<p data-id="'+info.id+'">'+info.name+'</p>';
            })
            $("#resultName").html(html);
        }else{
            $("#resultName").html("<p></p>");
        }
      }
  })
  $("#resultName").show();
  $("body").addClass("noscroll");
});
$("#resultName").on("click",function(){
  $(this).hide();
  $("body").removeClass("noscroll");
})
$("#resultName").on("click","p",function(){
  var id = $(this).attr("data-id");
  $("#resultName").hide();
  location.href = "newList-detail.html#id="+id;
})

// 获取首页轮播图
~function getSlide(){
  $.ajax({
      type:'get',
      url:address+'/slide/listSlides.do?sence=15&format=true',
      data:{},
      dataType:'json',
      success:function(result){
        if(result.status ==200){
          $("#slide").html(listSlides(result.data));
          slide($("#slide"));
        }
      }
  })
}();
function listSlides(data){
  var data = data.slideList,html='';
  html +='<ul class="slideBox">';
    $.each(data,function(index,info){
      html +='<li><a href="'+info.clickUrl+'"><div class="cover"></div><img src="'+info.image+'&size=640x300"></a></li>';
    })      
  html +='</ul><div class="point">';
  for(var i=0;i<data.length;i++){
    html += '<span></span>';
  }
  html +='</div>';
  return html;
};

// 获取七大板块图片
~function getHouseProperty(){
  $.ajax({
      type:'get',
      url:address+'/housePropertyHome/homeImages.do?format=true',
      data:{},
      dataType:'json',
      success:function(result){
        if(result.status ==200){
          $(".entranceIn").html(houseProperty(result.data));
        }
      }
  })
}();
function houseProperty(data){
  var info = data;
  html = '<a href="newList.html" class="new"><img src="'+info.houseproperty_new_buildings+'&size=196x196"></a>'+
    '<a href="oldList.html?listType=2" class="old"><img src="'+info.houseproperty_second_hand_house+'&size=196x196"></a>'+
    '<a href="oldList.html?listType=1" class="rent"><img src="'+info.houseproperty_rental_house+'&size=196x196"></a>'+
    '<a href="bussinessList.html" class="business"><img src="'+info.houseproperty_business_house+'&size=196x196"></a>'+
    '<a href="0" class="property"><img src="'+info.houseproperty_property+'&size=196×196"></a>'+
    '<a href="message.html" class="message"><img src="'+info.houseproperty_consultation+'&size=196x196"></a>'+
    '<a href="groupPurchase.html" class="group"><img src="'+info.houseproperty_group_buying+'&size=196x196"></a>';
  return html;
};
$("#entranceIn, .sellHouseMenu").on("click","a",function(e){
    e.stopPropagation();
    e.preventDefault();
    var enterUrl = $(this).attr("href");
    if(enterUrl =="0") {
      message("该功能正在开发中");
    }else{
      location.href = enterUrl;
    }
});

var pageSize = 10,pageNum = 1;

getGuess();
// 猜你喜欢
function getGuess(){
  $.ajax({
      type:'POST',
      url:address+'/housePropertyHome/guess.do',
      data:{
        "pageSize":pageSize,
        "pageNum":pageNum
      },
      dataType:'json',
      success:function(result){
        if(result.status ==200){
          $("#guess").html(newlistTPL(result.data));
        }else{
          var html = '<div class="nodata">没有数据</div>';
          $("#guess").html(html);
        }
      },
      error:function(result){
        message(result.message)
      }
  })
};


//获取城市列表
~function cityList(){
  $.ajax({
      type:'POST',
      url:address+'/houseCity/list.do?format=true',
      data:{},
      dataType:'json',
      success:function(result){
        if(result.status ==200){
          var html ="",arr =[];
          $.each(result.data.list,function(index,info){
              if(arr.length !=0 && info.key == arr[0]){
                html += '<p>'+info.value+'</p>';
              }else{
                arr.length = 0;
                arr.push(info.key);
                html += '<div class="bg-gray" id="'+info.key+'">'+info.key+'</div>'+
                '<p>'+info.value+'</p>';
              }
          })
          $("#cityList").html(html);
        }
      }
  })
}();

$("#cCity").on("click",function(){
  $("#chooseCity").show();
})
$("#chooseCity").on("click","p",function(){
  var city = $(this).text();
  $("#cCity").text(city);
  $("#chooseCity").hide();
  localStorage.setItem("cityName",city);
})


